<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/user/save">
    <div class="panel-body">
        <div class="form-group">
            <label class="col-sm-3 control-label">登录名：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="loginName" name="loginName"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">密码：</label>
            <div class="col-sm-9">
                <input type="password" class="col-sm-5" id="password" name="password"/>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">确认密码：</label>
            <div class="col-sm-9">
                <input type="password" class="col-sm-5" id="confirmPassword" name="confirmPassword"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">用户姓名：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userName" name="userName"/>
            </div>
        </div>
        
        <div class="form-group">
            <label class="col-sm-3 control-label">员工工号：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userNumber" name="userNumber"/>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">所属部门：</label>
            <div class="col-sm-9">
                <input class="col-sm-5" type="text" name="orgName" id="orgName" readonly="true"/>
                <input type="hidden" name="orgId" id="orgId"/>
                <button type="button" id="chooseOrgBtn" class="btn btn-danger">选择部门</button>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">角色：</label>
            <div class="col-sm-9">
                <input class="col-sm-5" type="text" name="roleName" id="roleName" value="一般人员" readonly="true"/>
                <input type="hidden" name="roleId" id="roleId" value="2"/>
                <button type="button" id="chooseRoleBtn" class="btn btn-danger">选择角色</button>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">性别：</label>
            <div class="col-sm-9">
                    <div class="radio">
                        <label class="col-sm-2">
                            <input type="radio" class="ace ace-ie" name="userSex" value="1" checked/>
                            <span class="lbl">男</span>
                        </label>
                        <label class="col-sm-2">
                            <input type="radio" class="ace ace-ie" name="userSex" value="2"/>
                            <span class="lbl">女</span>
                        </label>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">用户级别：</label>
            <div class="col-sm-9">
                <select class="col-sm-5" id="level" name="level">
                    <option value="1" selected="selected">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">显示顺序：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="inOrder" name="inOrder"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">身份证号：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userCertificateNo" name="userCertificateNo"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">邮箱：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userEmail" name="userEmail"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">手机：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userMobileNo" name="userMobileNo"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">固话：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userPhoneNo" name="userPhoneNo"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">地址：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userAddress" name="userAddress">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">邮政编码：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userPostCode" name="userPostCode"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">QQ：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userQq" name="userQq"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">其它社交公具号：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userOtherHm" name="userOtherHm"/>
            </div>
        </div>
        <button id="submit" type="submit" class="btn btn-primary btn-submit">提交</button>
    </div>
</form>
<script src="${basePath}/js/common/jquery.validator.addmethod.js${VERSION}"></script>
<script type="text/javascript">
    jQuery(function ($) {
    	
    	
    	if(parent.userOrgId){
    		$("#orgName").val(parent.userOrgName);
    		$("#orgId").val(parent.userOrgId);
    	}
    	
    	
    	
        var $form = $("#form");
        var $loginName = $("#loginName");
        var $password = $("#password");
        var $confirmPassword = $("#confirmPassword");
        var $userName = $("#userName");
        var $orgName = $("#orgName");
        var $roleName = $("#roleName");
        var $userCertificateNo = $("#userCertificateNo");
        var $userEmail = $("#userEmail");
        var $userMobileNo = $("#userMobileNo");
        var $userPhoneNo = $("#userPhoneNo");
        var $userPostCode = $("#userPostCode");
        var $userQq = $("#userQq");
        var $submit = $("#submit");
        var $level = $("#level");

        $form.validate({
            errorClass: 'error-msg',
            rules: {
                loginName:{
                    required:true,
                    remote: {
                        type: "post",
                        url: "${basePath}/user/check",
                        data: {
                            loginName: function() {
                                return $("#loginName").val();
                            }
                        },
                        dataType: "json",
                        dataFilter: function(data, type) {
                            var json = eval('('+data+')');
                            if(json.status == '0'){
                                return true;
                            } else {
                                return false;
                            }
                        }
                    }
                },
                password: {
                    required: true,
                    minlength: 6
                },
                confirmPassword: {
                    required: true,
                    minlength: 6,
                    equalTo: "#password"
                },
                userName: "required",
                orgName: "required",
                roleName: "required",
                userCertificateNo:
                    {
                    required: true,
                    isIdCardNo: true
                    },
                userEmail:"email",
                userMobileNo:"isMobile",
                userPhoneNo:"isTelphone",
                userPostCode:"isZipCode",
                userQq:"isQq",
                level: "required"
            },
            messages: {
                loginName: {
                    required: "登录名必填",
                    remote: "登录名已存在"
                },
                password: {
                    required: "密码必填",
                    minlength: "密码最少6位"
                },
                confirmPassword: {
                    required: "确认密码必填",
                    minlength: "密码最少6位",
                    equalTo: "与密码不一致"
                },
                userName: "用户姓名不能为空",
                orgName: "部门不能为空",
                roleName: "角色不能为空",
                userCertificateNo:
                {
                    required: "身份证必填",
                    isIdCardNo: "身份证号格式不正确"
                },
                userEmail:"邮箱格式不正确",
                userMobileNo:"手机格式不正确",
                userPhoneNo:"固话格式不正确",
                userPostCode:"邮编格式不正确",
                userQq:"QQ格式不正确",
                level: "级别必选"
            },
            submitHandler: function (form) {
                $.ajax({
                    url: $form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function () {
                        $submit.prop("disabled", true);
                    },
                    success: function (data) {
                        if (data.status == '0') {
                            $submit.prop("disabled", false);
                            layer.confirm('用户添加成功！是否关闭窗口？', {icon: 1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageii);
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });

        $('#chooseOrgBtn').click("click", function () {
            openOrg();

        });

        //选择部门
        function openOrg() {
            var pageii = layer.open({
                title: false,
                type: 2,
                area: ["300px", "400px"],
                content: ['${basePath}/org/toOrgTree'],
                btn: ["确认", "关闭"],
                yes: function (index, layero) {
                    var orgName = $(layero).find("iframe")[0].contentWindow.orgName;
                    var orgId = $(layero).find("iframe")[0].contentWindow.orgId;
                    layer.close(index);
                    $("#orgName").val(orgName);
                    $("#orgId").val(orgId);
                }, cancel: function () {
                    return true;
                }
            });
        }

        $('#chooseRoleBtn').click("click", function () {
            openRole();

        });

        //选择角色
        function openRole(){
            var pageii = layer.open({
                title: false,
                type: 2,
                area: ["90%", "80%"],
                content: ['${basePath}/role/toRoleChoose'],
                btn: ["确认", "关闭"],
                yes: function (index, layero) {
                    var roleName = $(layero).find("iframe")[0].contentWindow.roleName;
                    var roleId = $(layero).find("iframe")[0].contentWindow.roleId;
                    layer.close(index);
                    $("#roleName").val(roleName);
                    $("#roleId").val(roleId);
                }, cancel: function () {
                    return true;
                }
            });
        }

    });
</script>
</body>
</html>
